package com.AdvancedDemos.继承;

public class 继承 {
    public static void main(String[] args) {
        Student stu = new Student();
        stu.setAge(18);
        stu.getName();//调用父类Getter Setter访问private属性
        stu.study();//调用自身特有函数
        stu.eat();//来自父类函数

        /**
         * 格式: class 子类 extends 父类
         * Java中的类只支持单继承,不支持多继承,即一个类只能继承一个父类
         *
         * 父类也可以继承其他类,形成继承链 
         */


    }
}


class Person {
    //私有属性只能在本类中调用,子类中也不可见,可以用父类中的Getter/Setter
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat() {
        System.out.println("eat");
    }

    public void sleep() {
        System.out.println("sleep");
    }
}

class Student extends Person {
    public void study() {
        System.out.println("study");
    }
}

class Teacher1 extends Person {
    public void teach() {
        System.out.println("teach");
    }
}